import {COUNTER_INCREMENT, COUNTER_DECREMENT} from '../mutation-types';

const state = {
  count: 0
};

const getters = {
  realCount: (state) => {
    const count = state.count;
    return count + 1;
  }
};

const mutations = {
  [COUNTER_INCREMENT](state) {
    state.count += 1;
  },
  [COUNTER_DECREMENT](state) {
    state.count -= 1;
  },
  addFivePlus(state) {
    state.count += 5;
  }
};

const actions = {
  [COUNTER_INCREMENT]({ commit }) {
    setTimeout(() => {
      commit(COUNTER_INCREMENT);
    }, 500);
  },
  addFivePlus({ commit }) {
    commit('addFivePlus');
  }
};

export default {
  namespaced: true,
  state,
  mutations,
  getters,
  actions
};
